package lineareListen;

import java.util.NoSuchElementException;

public class AStack
{
    private final int n = 20;

    private int stackpointer = -1;

    private Object stack[] = new Object[n];

    boolean isEmpty()
    {
        return stackpointer == -1;
    }

    void push(Object newObject)
    {
        stackpointer++;
        if (stackpointer == stack.length)
        {
            Object neu[] = new Object[stack.length];
            for (int i = 0; i < stack.length; i++)
            {
                neu[i] = stack[i];
            }
            stack = neu;
        }
        stack[stackpointer] = newObject;
    }

    Object pop()
    {
        if (isEmpty())
        {
            throw new NoSuchElementException("pop() for empty stack");
        }
        stackpointer--;
        return stack[stackpointer + 1];
    }
}
